package net.tv90.bfmccore.game.view;

import lk.vexview.api.VexViewAPI;
import lk.vexview.builders.GuiBuilder;
import lk.vexview.gui.OpenedVexGui;
import lk.vexview.gui.VexGui;
import lk.vexview.gui.components.ButtonFunction;
import lk.vexview.gui.components.VexComponents;
import lk.vexview.gui.components.VexHoverText;
import net.tv90.bfmccore.game.GameManager;
import net.tv90.bfmccore.game.GameType;
import net.tv90.bfmccore.game.impl.AirSuperiorityGame;
import net.tv90.bfmccore.game.impl.ConquestGame;
import net.tv90.bfmccore.game.impl.cq.IVehicleSpawnConquestArea;
import net.tv90.bfmccore.game.impl.cq.VehicleSpawn;
import net.tv90.bfmccore.helper.FactionHelper;
import net.tv90.bfmccore.helper.MCHHelper;
import net.tv90.bfmccore.squad.Squad;
import net.tv90.bfmccore.util.Cooldown;
import net.tv90.bfmccore.util.TempPermission;
import org.bukkit.Bukkit;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;

import java.util.*;

import static net.tv90.bfmccore.game.EnumGameType.*;
import static net.tv90.bfmccore.helper.FactionHelper.*;
import static net.tv90.bfmccore.slot.SlotHelper.giveSlot;

public class GameModelViewHandler {
    public static volatile GameModelViewHandler instance;
    /**
     * 服务端与客户端VexView连接成功
     */
    public static Set<String> vexViewVerificationPlayers = new HashSet<>();

    public void refreshMainGUI(Player p) {
        OpenedVexGui vexGui = VexViewAPI.getPlayerCurrentGui(p);
        if(vexGui != null) {
            createMainGUI(p);
        }
    }

    public void createMainGUI(Player p) {
        if (!vexViewVerificationPlayers.contains(p.getName())) return;
        switch (GameManager.getInstance().currentGame.gameType) {
            case SDM: {
                createSDMMainGUI(p);
                break;
            }
            case START:
            case TDM: {
                createTDMMainGUI(p);
                break;
            }
            case GUNMASTER: {
                createGUNMASTERMainGUI(p);
                break;
            }
            case FRONTLINE:
            case VEHICLE_STORM:
            case CONQUEST: {
                createCONQUESTMainGUI(p, (ConquestGame) GameManager.getInstance().currentGame);
                break;
            }
            case AIR_SUPERIORITY: {
                createAIRSUPERIORITYMainGUI(p, (AirSuperiorityGame) GameManager.getInstance().currentGame);
                break;
            }
            default:
                throw new RuntimeException("Undefined Game Mode");
        }
    }

    public void createSelectFactionGUI(Player p, String firstFactionName, String secondFactionName) {
        int windowWidth = VexViewAPI.getPlayerClientWindowWidth(p);
        int windowHeight = VexViewAPI.getPlayerClientWindowHeight(p);
        VexGui gui = GuiBuilder.builder()
                .image(img -> img.location(110 * windowWidth / 854, -1).background("[local]BattleField/" + firstFactionName + ".png").size(200 * windowWidth / 854, 200 * windowHeight / 445))
                .image(img -> img.location(550 * windowWidth / 854, -1).background("[local]BattleField/" + secondFactionName + ".png").size(200 * windowWidth / 854, 200 * windowHeight / 445))
                .button(btn -> btn
                        .id("FirstFactionSelectButton")
                        .background("[local]GUI/button.png", "[local]GUI/button_focus.png")
                        .unClickable("[local]GUI/button_unclickable.png")
                        .size(100 * windowWidth / 854, 30 * windowHeight / 445)
                        .location(160 * windowWidth / 854, 350 * windowHeight / 445)
                        .text("加入" + getCountry_Lang2(firstFactionName))
                        .clickable(true)
                        .click(GameManager.getInstance().currentGame::joinFirstFaction))
                .button(btn -> btn
                        .id("SecondFactionSelectButton")
                        .background("[local]GUI/button.png", "[local]GUI/button_focus.png")
                        .unClickable("[local]GUI/button_unclickable.png")
                        .size(100 * windowWidth / 854, 30 * windowHeight / 445)
                        .location(600 * windowWidth / 854, 350 * windowHeight / 445)
                        .text("加入" + getCountry_Lang2(secondFactionName))
                        .clickable(true)
                        .click(GameManager.getInstance().currentGame::joinSecondFaction))
                .closable(false)
                .size(windowWidth, windowHeight)
                .build("[local]GUI/main.png", -1, -1);
        VexViewAPI.openGui(p, gui);
    }

    @GameType(TDM)
    public void createTDMMainGUI(Player p) {
        int windowWidth = VexViewAPI.getPlayerClientWindowWidth(p);
        int windowHeight = VexViewAPI.getPlayerClientWindowHeight(p);
        String kit = getKit2(p);
        String country = getCountry2(p);
        if (country == null || country.equals("NoFaction")) {
            return;
        }
        VexGui gui = GuiBuilder.builder()
                .size(windowWidth, windowHeight)
                .image(img -> img
                        .background("[local]BattleField/map/" + GameManager.getInstance().currentGame.mapName + ".png")
                        .size(791 * windowWidth / 854, 400 * windowHeight / 445)
                        .location(-1, -1))
                .image(img -> img
                        .background("[local]BFMC/" + country + ".png")
                        .size(50 * windowWidth / 854, 50 * windowHeight / 445)
                        .location(30 * windowWidth / 854, 330 * windowHeight / 445))
                //取消按钮
                .button(btn -> btn
                        .id("Cancel")
                        .background("[local]GUI/button_cancel.png", "[local]GUI/button_cancel_focus.png")
                        .unClickable("[local]GUI/button_cancel_focus.png")
                        .size(30 * windowWidth / 854, 30 * windowHeight / 445)
                        .location(819 * windowWidth / 854, 5 * windowHeight / 445)
                        .text("")
                        .clickable(true)
                        .click(this::cancelMainMenu))
                //换阵营按钮
                .button(btn -> btn
                        .id("FactionChangeButton")
                        .background("[local]GUI/button.png", "[local]GUI/button_focus.png")
                        .unClickable("[local]GUI/button_unclickable.png")
                        .size(100 * windowWidth / 854, 30 * windowHeight / 445)
                        .location(30 * windowWidth / 854, 390 * windowHeight / 445)
                        .text("切换阵营")
                        .clickable(true)
                        .click(this::changeFaction))
                //部署至战场按钮
                .button(btn -> btn
                        .id("DeployButton")
                        .background("[local]GUI/button.png", "[local]GUI/button_focus.png")
                        .unClickable("[local]GUI/button_unclickable.png")
                        .size(100 * windowWidth / 854, 30 * windowHeight / 445)
                        .location(720 * windowWidth / 854, 380 * windowHeight / 445)
                        .text("随机部署至战场" + (Cooldown.getTime("Deploy", p) > 0 ? Cooldown.getTime("Deploy", p) : "0") + ".0s")
                        .clickable(true)
                        .click(this::deploy))
                //部署至小队长按钮
                .button(btn -> btn
                        .id("SquadDeployButton")
                        .background("[local]GUI/button.png", "[local]GUI/button_focus.png")
                        .unClickable("[local]GUI/button_unclickable.png")
                        .size(100 * windowWidth / 854, 30 * windowHeight / 445)
                        .location(720 * windowWidth / 854, 340 * windowHeight / 445)
                        .text("部署至小队长 " + (Cooldown.getTime("Teleport", p) > 0 ? Cooldown.getTime("Teleport", p) : "0") + ".0s")
                        .clickable(true)
                        .click(Squad::teleportToLeader))
                //突击兵按钮
                .button(btn -> btn
                        .id("ASSButton")
                        .background(kit.equals("ASS") ? "[local]GUI/button_orange.png" : "[local]GUI/button.png"
                                , kit.equals("ASS") ? "[local]GUI/button_orange_focus.png" : "[local]GUI/button_focus.png")
                        .unClickable("[local]GUI/button_unclickable.png")
                        .size(100 * windowWidth / 854, 30 * windowHeight / 445)
                        .location(200 * windowWidth / 854, 10 * windowHeight / 445)
                        .text("突击兵")
                        .clickable(true)
                        .click(this::setASS))
                //侦察兵按钮
                .button(btn -> btn
                        .id("RECButton")
                        .background(kit.equals("REC") ? "[local]GUI/button_orange.png" : "[local]GUI/button.png"
                                , kit.equals("REC") ? "[local]GUI/button_orange_focus.png" : "[local]GUI/button_focus.png")
                        .unClickable("[local]GUI/button_unclickable.png")
                        .size(100 * windowWidth / 854, 30 * windowHeight / 445)
                        .location(310 * windowWidth / 854, 10 * windowHeight / 445)
                        .text("侦察兵")
                        .clickable(true)
                        .click(this::setREC))
                //支援兵按钮
                .button(btn -> btn
                        .id("SUPButton")
                        .background(kit.equals("SUP") ? "[local]GUI/button_orange.png" : "[local]GUI/button.png"
                                , kit.equals("SUP") ? "[local]GUI/button_orange_focus.png" : "[local]GUI/button_focus.png")
                        .unClickable("[local]GUI/button_unclickable.png")
                        .size(100 * windowWidth / 854, 30 * windowHeight / 445)
                        .location(420 * windowWidth / 854, 10 * windowHeight / 445)
                        .text("支援兵")
                        .clickable(true)
                        .click(this::setSUP))
                //工程兵按钮
                .button(btn -> btn
                        .id("ENGButton")
                        .background(kit.equals("ENG") ? "[local]GUI/button_orange.png" : "[local]GUI/button.png"
                                , kit.equals("ENG") ? "[local]GUI/button_orange_focus.png" : "[local]GUI/button_focus.png")
                        .unClickable("[local]GUI/button_unclickable.png")
                        .size(100 * windowWidth / 854, 30 * windowHeight / 445)
                        .location(530 * windowWidth / 854, 10 * windowHeight / 445)
                        .text("工程兵")
                        .clickable(true)
                        .click(this::setENG))
                //背包设置按钮
                .button(btn -> btn
                        .id("SlotSetting")
                        .background("[local]GUI/button_setting.png", "[local]GUI/button_setting_focus.png")
                        .unClickable("[local]GUI/button_setting_focus.png")
                        .size(30 * windowWidth / 854, 30 * windowHeight / 445)
                        .location(650 * windowWidth / 854, 10 * windowHeight / 445)
                        .text("")
                        .clickable(true)
                        .click(this::openSlotSetting))
                //小队设置按钮
                .button(btn -> btn
                        .id("SquadSetting")
                        .background("[local]GUI/button.png", "[local]GUI/button_focus.png")
                        .unClickable("[local]GUI/button_unclickable.png")
                        .size(100 * windowWidth / 854, 30 * windowHeight / 445)
                        .location(50 * windowWidth / 854, 30 * windowHeight / 445)
                        .text("队伍设置")
                        .clickable(true)
                        .click(this::openSquadSetting))
                .closable(false)
                .build("[local]GUI/main.png", -1, -1);
        VexViewAPI.openGui(p, gui);
    }

    @GameType(GUNMASTER)
    public void createGUNMASTERMainGUI(Player p) {
        int windowWidth = VexViewAPI.getPlayerClientWindowWidth(p);
        int windowHeight = VexViewAPI.getPlayerClientWindowHeight(p);
        String kit = getKit2(p);
        String country = getCountry2(p);
        if (country == null || country.equals("NoFaction")) {
            return;
        }
        VexGui gui = GuiBuilder.builder()
                .size(windowWidth, windowHeight)
                .image(img -> img
                        .background("[local]BattleField/map/" + GameManager.getInstance().currentGame.mapName + ".png")
                        .size(791 * windowWidth / 854, 400 * windowHeight / 445)
                        .location(-1, -1))
                .image(img -> img
                        .background("[local]BFMC/" + country + ".png")
                        .size(50 * windowWidth / 854, 50 * windowHeight / 445)
                        .location(30 * windowWidth / 854, 330 * windowHeight / 445))
                //换阵营按钮
                .button(btn -> btn
                        .id("FactionChangeButton")
                        .background("[local]GUI/button.png", "[local]GUI/button_focus.png")
                        .unClickable("[local]GUI/button_unclickable.png")
                        .size(100 * windowWidth / 854, 30 * windowHeight / 445)
                        .location(30 * windowWidth / 854, 390 * windowHeight / 445)
                        .text("切换阵营")
                        .clickable(true)
                        .click(this::changeFaction))
                .button(btn -> btn
                        .id("Cancel")
                        .background("[local]GUI/button_cancel.png", "[local]GUI/button_cancel_focus.png")
                        .unClickable("[local]GUI/button_cancel_focus.png")
                        .size(30 * windowWidth / 854, 30 * windowHeight / 445)
                        .location(819 * windowWidth / 854, 5 * windowHeight / 445)
                        .text("")
                        .clickable(true)
                        .click(this::cancelMainMenu))
                //部署至战场按钮
                .button(btn -> btn
                        .id("DeployButton")
                        .background("[local]GUI/button.png", "[local]GUI/button_focus.png")
                        .unClickable("[local]GUI/button_unclickable.png")
                        .size(100 * windowWidth / 854, 30 * windowHeight / 445)
                        .location(720 * windowWidth / 854, 380 * windowHeight / 445)
                        .text("随机部署至战场" + (Cooldown.getTime("Deploy", p) > 0 ? Cooldown.getTime("Deploy", p) : "0") + ".0s")
                        .clickable(true)
                        .click(this::deploy))
                //部署至小队长按钮
                .button(btn -> btn
                        .id("SquadDeployButton")
                        .background("[local]GUI/button.png", "[local]GUI/button_focus.png")
                        .unClickable("[local]GUI/button_unclickable.png")
                        .size(100 * windowWidth / 854, 30 * windowHeight / 445)
                        .location(720 * windowWidth / 854, 340 * windowHeight / 445)
                        .text("部署至小队长")
                        .clickable(false)
                        .click(Squad::teleportToLeader))
                .closable(false)
                .build("[local]GUI/main.png", -1, -1);
        VexViewAPI.openGui(p, gui);
    }

    @GameType(SDM)
    public void createSDMMainGUI(Player p) {
        int windowWidth = VexViewAPI.getPlayerClientWindowWidth(p);
        int windowHeight = VexViewAPI.getPlayerClientWindowHeight(p);
        String kit = getKit2(p);
        String country = getCountry2(p);
        if (country == null || country.equals("NoFaction")) {
            return;
        }

        VexGui gui = GuiBuilder.builder()
                .size(windowWidth, windowHeight)
                .image(img -> img
                        .background("[local]BattleField/map/" + GameManager.getInstance().currentGame.mapName + ".png")
                        .size(791 * windowWidth / 854, 400 * windowHeight / 445)
                        .location(-1, -1))
                .image(img -> img
                        .background("[local]BFMC/" + country + ".png")
                        .size(50 * windowWidth / 854, 50 * windowHeight / 445)
                        .location(30 * windowWidth / 854, 330 * windowHeight / 445))
                //换阵营按钮
                .button(btn -> btn
                        .id("FactionChangeButton")
                        .background("[local]GUI/button.png", "[local]GUI/button_focus.png")
                        .unClickable("[local]GUI/button_unclickable.png")
                        .size(100 * windowWidth / 854, 30 * windowHeight / 445)
                        .location(30 * windowWidth / 854, 390 * windowHeight / 445)
                        .text("切换阵营")
                        .clickable(true)
                        .click(this::changeFaction))
                .button(btn -> btn
                        .id("Cancel")
                        .background("[local]GUI/button_cancel.png", "[local]GUI/button_cancel_focus.png")
                        .unClickable("[local]GUI/button_cancel_focus.png")
                        .size(30 * windowWidth / 854, 30 * windowHeight / 445)
                        .location(819 * windowWidth / 854, 5 * windowHeight / 445)
                        .text("")
                        .clickable(true)
                        .click(this::cancelMainMenu))
                //部署至战场按钮
                .button(btn -> btn
                        .id("DeployButton")
                        .background("[local]GUI/button.png", "[local]GUI/button_focus.png")
                        .unClickable("[local]GUI/button_unclickable.png")
                        .size(100 * windowWidth / 854, 30 * windowHeight / 445)
                        .location(720 * windowWidth / 854, 380 * windowHeight / 445)
                        .text("小队长部署" + (Cooldown.getTime("Deploy", p) > 0 ? Cooldown.getTime("Deploy", p) : "0") + ".0s")
                        .clickable(TempPermission.hasTempPerm(p, "bfmc.squadleader"))
                        .click(this::deploy))
                //部署至小队长按钮
                .button(btn -> btn
                        .id("SquadDeployButton")
                        .background("[local]GUI/button.png", "[local]GUI/button_focus.png")
                        .unClickable("[local]GUI/button_unclickable.png")
                        .size(100 * windowWidth / 854, 30 * windowHeight / 445)
                        .location(720 * windowWidth / 854, 340 * windowHeight / 445)
                        .text("队员部署" + (Cooldown.getTime("Teleport", p) > 0 ? Cooldown.getTime("Teleport", p) : "0") + ".0s")
                        .clickable(!TempPermission.hasTempPerm(p, "bfmc.squadleader"))
                        .click(Squad::teleportToLeader))
                //突击兵按钮
                .button(btn -> btn
                        .id("ASSButton")
                        .background(kit.equals("ASS") ? "[local]GUI/button_orange.png" : "[local]GUI/button.png"
                                , kit.equals("ASS") ? "[local]GUI/button_orange_focus.png" : "[local]GUI/button_focus.png")
                        .unClickable("[local]GUI/button_unclickable.png")
                        .size(100 * windowWidth / 854, 30 * windowHeight / 445)
                        .location(200 * windowWidth / 854, 10 * windowHeight / 445)
                        .text("突击兵")
                        .clickable(true)
                        .click(this::setASS))
                //侦察兵按钮
                .button(btn -> btn
                        .id("RECButton")
                        .background(kit.equals("REC") ? "[local]GUI/button_orange.png" : "[local]GUI/button.png"
                                , kit.equals("REC") ? "[local]GUI/button_orange_focus.png" : "[local]GUI/button_focus.png")
                        .unClickable("[local]GUI/button_unclickable.png")
                        .size(100 * windowWidth / 854, 30 * windowHeight / 445)
                        .location(310 * windowWidth / 854, 10 * windowHeight / 445)
                        .text("侦察兵")
                        .clickable(true)
                        .click(this::setREC))
                //支援兵按钮
                .button(btn -> btn
                        .id("SUPButton")
                        .background(kit.equals("SUP") ? "[local]GUI/button_orange.png" : "[local]GUI/button.png"
                                , kit.equals("SUP") ? "[local]GUI/button_orange_focus.png" : "[local]GUI/button_focus.png")
                        .unClickable("[local]GUI/button_unclickable.png")
                        .size(100 * windowWidth / 854, 30 * windowHeight / 445)
                        .location(420 * windowWidth / 854, 10 * windowHeight / 445)
                        .text("支援兵")
                        .clickable(true)
                        .click(this::setSUP))
                //工程兵按钮
                .button(btn -> btn
                        .id("ENGButton")
                        .background(kit.equals("ENG") ? "[local]GUI/button_orange.png" : "[local]GUI/button.png"
                                , kit.equals("ENG") ? "[local]GUI/button_orange_focus.png" : "[local]GUI/button_focus.png")
                        .unClickable("[local]GUI/button_unclickable.png")
                        .size(100 * windowWidth / 854, 30 * windowHeight / 445)
                        .location(530 * windowWidth / 854, 10 * windowHeight / 445)
                        .text("工程兵")
                        .clickable(true)
                        .click(this::setENG))
                //背包设置按钮
                .button(btn -> btn
                        .id("SlotSetting")
                        .background("[local]GUI/button_setting.png", "[local]GUI/button_setting_focus.png")
                        .unClickable("[local]GUI/button_setting_focus.png")
                        .size(30 * windowWidth / 854, 30 * windowHeight / 445)
                        .location(650 * windowWidth / 854, 10 * windowHeight / 445)
                        .text("")
                        .clickable(true)
                        .click(this::openSlotSetting))
                //小队设置按钮
                .button(btn -> btn
                        .id("SquadSetting")
                        .background("[local]GUI/button.png", "[local]GUI/button_focus.png")
                        .unClickable("[local]GUI/button_unclickable.png")
                        .size(100 * windowWidth / 854, 30 * windowHeight / 445)
                        .location(50 * windowWidth / 854, 30 * windowHeight / 445)
                        .text("队伍设置")
                        .clickable(true)
                        .click(this::openSquadSetting))
                .closable(false)
                .build("[local]GUI/main.png", -1, -1);
        VexViewAPI.openGui(p, gui);
    }

    @GameType(CONQUEST)
    public void createCONQUESTMainGUI(Player p, ConquestGame conquestGame) {
        int windowWidth = VexViewAPI.getPlayerClientWindowWidth(p);
        int windowHeight = VexViewAPI.getPlayerClientWindowHeight(p);
        String kit = getKit2(p);
        String country = getCountry2(p);
        if (country == null || country.equals("NoFaction")) return;
        try {
            List<VexComponents> vexComponentsList = new ArrayList<>();
            conquestGame.conquestAreaList.forEach((C, I) -> {
                String redOrBlue;
                if (C.currentFaction.equals("NEUTRALIZED")) {
                    redOrBlue = "Null";
                    //C.conquestAreaButton.addFunction(this::cannotDeploy);
                } else if (C.currentFaction.equals(getCountry2(p))) {
                    redOrBlue = "Blue";
                    //C.conquestAreaButton.addFunction(C::teleportPlayerToConquestArea);
                } else {
                    redOrBlue = "Red";
                    //C.conquestAreaButton.addFunction(this::cannotDeploy);
                }
                C.conquestAreaButton.addFunction(C::teleportPlayerToConquestArea);
                vexComponentsList.add(C.conquestAreaButton.getVexComponents(redOrBlue, windowWidth, windowHeight));
            });

            //vexComponentsList.forEach(vexButton -> System.out.println("SHOW X:" + vexButton.getX() + " Y:" + vexButton.getY()));

            VexGui gui = GuiBuilder.builder()
                    .size(windowWidth, windowHeight)
                    .image(img -> img
                            .background("[local]BattleField/map/" + GameManager.getInstance().currentGame.mapName + ".png")
                            .size(791 * windowWidth / 854, 400 * windowHeight / 445)
                            .location(-1, -1))
                    .image(img -> img
                            .background("[local]BFMC/" + country + ".png")
                            .size(50 * windowWidth / 854, 50 * windowHeight / 445)
                            .location(30 * windowWidth / 854, 330 * windowHeight / 445))
                    //取消按钮
                    .button(btn -> btn
                            .id("Cancel")
                            .background("[local]GUI/button_cancel.png", "[local]GUI/button_cancel_focus.png")
                            .unClickable("[local]GUI/button_cancel_focus.png")
                            .size(30 * windowWidth / 854, 30 * windowHeight / 445)
                            .location(819 * windowWidth / 854, 5 * windowHeight / 445)
                            .text("")
                            .clickable(true)
                            .click(this::cancelMainMenu))
                    //换阵营按钮
                    .button(btn -> btn
                            .id("FactionChangeButton")
                            .background("[local]GUI/button.png", "[local]GUI/button_focus.png")
                            .unClickable("[local]GUI/button_unclickable.png")
                            .size(100 * windowWidth / 854, 30 * windowHeight / 445)
                            .location(30 * windowWidth / 854, 390 * windowHeight / 445)
                            .text("切换阵营")
                            .clickable(true)
                            .click(this::changeFaction))
                    //部署至战场按钮
                    .button(btn -> btn
                            .id("DeployButton")
                            .background("[local]GUI/button.png", "[local]GUI/button_focus.png")
                            .unClickable("[local]GUI/button_unclickable.png")
                            .size(100 * windowWidth / 854, 30 * windowHeight / 445)
                            .location(720 * windowWidth / 854, 380 * windowHeight / 445)
                            .text("点击蓝色占领点部署" + (Cooldown.getTime("Deploy", p) > 0 ? Cooldown.getTime("Deploy", p) : "0") + ".0s")
                            .clickable(false)
                            .click(this::deploy))
                    //部署至步战车
                    .button(btn -> btn
                            .id("IFVDeployButton")
                            .background("[local]GUI/MenuVehicleIFVXL.png", "[local]GUI/MenuVehicleIFVXL_1.png")
                            .unClickable("[local]GUI/MenuVehicleIFVXL_2.png")
                            .size(30 * windowWidth / 854, 30 * windowHeight / 445)
                            .location(680 * windowWidth / 854, 340 * windowHeight / 445)
                            .text("")
                            .hover(new VexHoverText(Collections.singletonList("部署至友军随机步战车")))
                            .clickable(GameManager.getInstance().currentGame.maxTankNum > 0)
                            .click((player) -> GameManager.getInstance().currentGame.deployOnRandomAircraftEntity(player, "IFV")))
                    //部署至轻型载具
                    .button(btn -> btn
                            .id("TransportDeployButton")
                            .background("[local]GUI/MenuVehicleJeepArmoredXL.png", "[local]GUI/MenuVehicleJeepArmoredXL_1.png")
                            .unClickable("[local]GUI/MenuVehicleJeepArmoredXL_2.png")
                            .size(30 * windowWidth / 854, 30 * windowHeight / 445)
                            .location(640 * windowWidth / 854, 340 * windowHeight / 445)
                            .text("")
                            .hover(new VexHoverText(Collections.singletonList("部署至友军随机轻型运输载具")))
                            .clickable(GameManager.getInstance().currentGame.maxLightVehicleNum > 0)
                            .click((player) -> GameManager.getInstance().currentGame.deployOnRandomAircraftEntity(player, "Transport")))
                    //部署至快艇
                    .button(btn -> btn
                            .id("FACDeployButton")
                            .background("[local]GUI/MenuVehicleBoatFastAttackXL.png", "[local]GUI/MenuVehicleBoatFastAttackXL_1.png")
                            .unClickable("[local]GUI/MenuVehicleBoatFastAttackXL_2.png")
                            .size(30 * windowWidth / 854, 30 * windowHeight / 445)
                            .location(680 * windowWidth / 854, 380 * windowHeight / 445)
                            .text("")
                            .hover(new VexHoverText(Collections.singletonList("部署至友军随机攻击快艇")))
                            .clickable(GameManager.getInstance().currentGame.maxFacNum > 0)
                            .click((player) -> GameManager.getInstance().currentGame.deployOnRandomAircraftEntity(player, "FAC")))
                    //部署至运输机
                    .button(btn -> btn
                            .id("ScoutHeliDeployButton")
                            .background("[local]GUI/MenuVehicleScoutHeliXL.png", "[local]GUI/MenuVehicleScoutHeliXL_1.png")
                            .unClickable("[local]GUI/MenuVehicleScoutHeliXL_2.png")
                            .size(30 * windowWidth / 854, 30 * windowHeight / 445)
                            .location(640 * windowWidth / 854, 380 * windowHeight / 445)
                            .text("")
                            .hover(new VexHoverText(Collections.singletonList("部署至友军随机运输直升机")))
                            .clickable(GameManager.getInstance().currentGame.maxTransHeliNum > 0)
                            .click((player) -> GameManager.getInstance().currentGame.deployOnRandomAircraftEntity(player, "ScoutHeli")))
                    //部署至小队长按钮
                    .button(btn -> btn
                            .id("SquadDeployButton")
                            .background("[local]GUI/button.png", "[local]GUI/button_focus.png")
                            .unClickable("[local]GUI/button_unclickable.png")
                            .size(100 * windowWidth / 854, 30 * windowHeight / 445)
                            .location(720 * windowWidth / 854, 340 * windowHeight / 445)
                            .text("部署至小队长 " + (Cooldown.getTime("Teleport", p) > 0 ? Cooldown.getTime("Teleport", p) : "0") + ".0s")
                            .clickable(true)
                            .click(Squad::teleportToLeader))
                    //突击兵按钮
                    .button(btn -> btn
                            .id("ASSButton")
                            .background(kit.equals("ASS") ? "[local]GUI/button_orange.png" : "[local]GUI/button.png"
                                    , kit.equals("ASS") ? "[local]GUI/button_orange_focus.png" : "[local]GUI/button_focus.png")
                            .unClickable("[local]GUI/button_unclickable.png")
                            .size(100 * windowWidth / 854, 30 * windowHeight / 445)
                            .location(200 * windowWidth / 854, 10 * windowHeight / 445)
                            .text("突击兵")
                            .clickable(true)
                            .click(this::setASS))
                    //侦察兵按钮
                    .button(btn -> btn
                            .id("RECButton")
                            .background(kit.equals("REC") ? "[local]GUI/button_orange.png" : "[local]GUI/button.png"
                                    , kit.equals("REC") ? "[local]GUI/button_orange_focus.png" : "[local]GUI/button_focus.png")
                            .unClickable("[local]GUI/button_unclickable.png")
                            .size(100 * windowWidth / 854, 30 * windowHeight / 445)
                            .location(310 * windowWidth / 854, 10 * windowHeight / 445)
                            .text("侦察兵")
                            .clickable(true)
                            .click(this::setREC))
                    //支援兵按钮
                    .button(btn -> btn
                            .id("SUPButton")
                            .background(kit.equals("SUP") ? "[local]GUI/button_orange.png" : "[local]GUI/button.png"
                                    , kit.equals("SUP") ? "[local]GUI/button_orange_focus.png" : "[local]GUI/button_focus.png")
                            .unClickable("[local]GUI/button_unclickable.png")
                            .size(100 * windowWidth / 854, 30 * windowHeight / 445)
                            .location(420 * windowWidth / 854, 10 * windowHeight / 445)
                            .text("支援兵")
                            .clickable(true)
                            .click(this::setSUP))
                    //工程兵按钮
                    .button(btn -> btn
                            .id("ENGButton")
                            .background(kit.equals("ENG") ? "[local]GUI/button_orange.png" : "[local]GUI/button.png"
                                    , kit.equals("ENG") ? "[local]GUI/button_orange_focus.png" : "[local]GUI/button_focus.png")
                            .unClickable("[local]GUI/button_unclickable.png")
                            .size(100 * windowWidth / 854, 30 * windowHeight / 445)
                            .location(530 * windowWidth / 854, 10 * windowHeight / 445)
                            .text("工程兵")
                            .clickable(true)
                            .click(this::setENG))
                    //背包设置按钮
                    .button(btn -> btn
                            .id("SlotSetting")
                            .background("[local]GUI/button_setting.png", "[local]GUI/button_setting_focus.png")
                            .unClickable("[local]GUI/button_setting_focus.png")
                            .size(30 * windowWidth / 854, 30 * windowHeight / 445)
                            .location(650 * windowWidth / 854, 10 * windowHeight / 445)
                            .text("")
                            .clickable(true)
                            .click(this::openSlotSetting))
                    //小队设置按钮
                    .button(btn -> btn
                            .id("SquadSetting")
                            .background("[local]GUI/button.png", "[local]GUI/button_focus.png")
                            .unClickable("[local]GUI/button_unclickable.png")
                            .size(100 * windowWidth / 854, 30 * windowHeight / 445)
                            .location(30 * windowWidth / 854, 30 * windowHeight / 445)
                            .text("队伍设置")
                            .clickable(true)
                            .click(this::openSquadSetting))
                    .closable(false)
                    .build("[local]GUI/main.png", -1, -1);
            vexComponentsList.forEach(gui::addComponent);
            VexViewAPI.openGui(p, gui);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @GameType(AIR_SUPERIORITY)
    public void createAIRSUPERIORITYMainGUI(Player p, AirSuperiorityGame conquestGame) {
        int windowWidth = VexViewAPI.getPlayerClientWindowWidth(p);
        int windowHeight = VexViewAPI.getPlayerClientWindowHeight(p);
        String kit = getKit2(p);
        String country = getCountry2(p);
        if (country == null || country.equals("NoFaction")) return;
        try {
            List<VexComponents> vexComponentsList = new ArrayList<>();
            conquestGame.conquestAreaList.forEach((C, I) -> {
                String redOrBlue;
                if (C.currentFaction.equals("NEUTRALIZED")) {
                    redOrBlue = "Null";
                    //C.conquestAreaButton.addFunction(this::cannotDeploy);
                } else if (C.currentFaction.equals(getCountry2(p))) {
                    redOrBlue = "Blue";
                    //C.conquestAreaButton.addFunction(C::teleportPlayerToConquestArea);
                } else {
                    redOrBlue = "Red";
                    //C.conquestAreaButton.addFunction(this::cannotDeploy);
                }
                C.conquestAreaButton.addFunction(C::teleportPlayerToConquestArea);
                vexComponentsList.add(C.conquestAreaButton.getVexComponents(redOrBlue, windowWidth, windowHeight));
                //C.conquestAreaButton.resetOriginalResolution();
            });

            //vexComponentsList.forEach(vexButton -> System.out.println("SHOW X:" + vexButton.getX() + " Y:" + vexButton.getY()));

            VexGui gui = GuiBuilder.builder()
                    .size(windowWidth, windowHeight)
                    .image(img -> img
                            .background("[local]BattleField/map/" + GameManager.getInstance().currentGame.mapName + ".png")
                            .size(791 * windowWidth / 854, 400 * windowHeight / 445)
                            .location(-1, -1))
                    .image(img -> img
                            .background("[local]BFMC/" + country + ".png")
                            .size(50 * windowWidth / 854, 50 * windowHeight / 445)
                            .location(30 * windowWidth / 854, 330 * windowHeight / 445))
                    //取消按钮
                    .button(btn -> btn
                            .id("Cancel")
                            .background("[local]GUI/button_cancel.png", "[local]GUI/button_cancel_focus.png")
                            .unClickable("[local]GUI/button_cancel_focus.png")
                            .size(30 * windowWidth / 854, 30 * windowHeight / 445)
                            .location(819 * windowWidth / 854, 5 * windowHeight / 445)
                            .text("")
                            .clickable(true)
                            .click(this::cancelMainMenu))
                    //换阵营按钮
                    .button(btn -> btn
                            .id("FactionChangeButton")
                            .background("[local]GUI/button.png", "[local]GUI/button_focus.png")
                            .unClickable("[local]GUI/button_unclickable.png")
                            .size(100 * windowWidth / 854, 30 * windowHeight / 445)
                            .location(30 * windowWidth / 854, 390 * windowHeight / 445)
                            .text("切换阵营")
                            .clickable(true)
                            .click(this::changeFaction))
                    //突击兵按钮
                    .button(btn -> btn
                            .id("ASSButton")
                            .background(kit.equals("ASS") ? "[local]GUI/button_orange.png" : "[local]GUI/button.png"
                                    , kit.equals("ASS") ? "[local]GUI/button_orange_focus.png" : "[local]GUI/button_focus.png")
                            .unClickable("[local]GUI/button_unclickable.png")
                            .size(100 * windowWidth / 854, 30 * windowHeight / 445)
                            .location(200 * windowWidth / 854, 10 * windowHeight / 445)
                            .text("突击兵")
                            .clickable(true)
                            .click(this::setASS))
                    //侦察兵按钮
                    .button(btn -> btn
                            .id("RECButton")
                            .background(kit.equals("REC") ? "[local]GUI/button_orange.png" : "[local]GUI/button.png"
                                    , kit.equals("REC") ? "[local]GUI/button_orange_focus.png" : "[local]GUI/button_focus.png")
                            .unClickable("[local]GUI/button_unclickable.png")
                            .size(100 * windowWidth / 854, 30 * windowHeight / 445)
                            .location(310 * windowWidth / 854, 10 * windowHeight / 445)
                            .text("侦察兵")
                            .clickable(true)
                            .click(this::setREC))
                    //支援兵按钮
                    .button(btn -> btn
                            .id("SUPButton")
                            .background(kit.equals("SUP") ? "[local]GUI/button_orange.png" : "[local]GUI/button.png"
                                    , kit.equals("SUP") ? "[local]GUI/button_orange_focus.png" : "[local]GUI/button_focus.png")
                            .unClickable("[local]GUI/button_unclickable.png")
                            .size(100 * windowWidth / 854, 30 * windowHeight / 445)
                            .location(420 * windowWidth / 854, 10 * windowHeight / 445)
                            .text("支援兵")
                            .clickable(true)
                            .click(this::setSUP))
                    //工程兵按钮
                    .button(btn -> btn
                            .id("ENGButton")
                            .background(kit.equals("ENG") ? "[local]GUI/button_orange.png" : "[local]GUI/button.png"
                                    , kit.equals("ENG") ? "[local]GUI/button_orange_focus.png" : "[local]GUI/button_focus.png")
                            .unClickable("[local]GUI/button_unclickable.png")
                            .size(100 * windowWidth / 854, 30 * windowHeight / 445)
                            .location(530 * windowWidth / 854, 10 * windowHeight / 445)
                            .text("工程兵")
                            .clickable(true)
                            .click(this::setENG))
                    //背包设置按钮
                    .button(btn -> btn
                            .id("SlotSetting")
                            .background("[local]GUI/button_setting.png", "[local]GUI/button_setting_focus.png")
                            .unClickable("[local]GUI/button_setting_focus.png")
                            .size(30 * windowWidth / 854, 30 * windowHeight / 445)
                            .location(650 * windowWidth / 854, 10 * windowHeight / 445)
                            .text("")
                            .clickable(true)
                            .click(this::openSlotSetting))
                    //小队设置按钮
                    .button(btn -> btn
                            .id("SquadSetting")
                            .background("[local]GUI/button.png", "[local]GUI/button_focus.png")
                            .unClickable("[local]GUI/button_unclickable.png")
                            .size(100 * windowWidth / 854, 30 * windowHeight / 445)
                            .location(50 * windowWidth / 854, 30 * windowHeight / 445)
                            .text("队伍设置")
                            .clickable(false)
                            .click(this::openSquadSetting))
                    //部署至战场按钮
                    .button(btn -> btn
                            .id("DeployButton")
                            .background("[local]GUI/button.png", "[local]GUI/button_focus.png")
                            .unClickable("[local]GUI/button_unclickable.png")
                            .size(100 * windowWidth / 854, 30 * windowHeight / 445)
                            .location(720 * windowWidth / 854, 380 * windowHeight / 445)
                            .text("点击蓝色占领点部署" + (Cooldown.getTime("Deploy", p) > 0 ? Cooldown.getTime("Deploy", p) : "0") + ".0s")
                            .clickable(false)
                            .click(this::deploy))
                    .closable(false)
                    .build("[local]GUI/main.png", -1, -1);
            vexComponentsList.forEach(gui::addComponent);
            VexViewAPI.openGui(p, gui);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void createInfoGui(Player p, String info, ButtonFunction func) {
        int windowWidth = VexViewAPI.getPlayerClientWindowWidth(p);
        int windowHeight = VexViewAPI.getPlayerClientWindowHeight(p);
        VexGui gui = GuiBuilder.builder()
                .size(250 * windowWidth / 854, 180 * windowHeight / 445)
                .text(txt -> txt
                        .location(-1, 50 * windowHeight / 445)
                        .addLine(info)
                        .scale(1.0F))
                .button(btn -> btn
                        .id("GUI_OK")
                        .background("[local]GUI/button.png", "[local]GUI/button_focus.png")
                        .unClickable("[local]GUI/button_unclickable.png")
                        .size(100 * windowWidth / 854, 30 * windowHeight / 445)
                        .location(75 * windowWidth / 854, 120 * windowHeight / 445)
                        .text("确定")
                        .clickable(true)
                        .click(func))
                .closable(false)
                .build("[local]GUI/info.png", -1, -1);
        VexViewAPI.openGui(p, gui);
    }

    public void createInfoGui(Player p, String info, ButtonFunction func1, ButtonFunction func2) {
        int windowWidth = VexViewAPI.getPlayerClientWindowWidth(p);
        int windowHeight = VexViewAPI.getPlayerClientWindowHeight(p);
        VexGui gui = GuiBuilder.builder()
                .size(250 * windowWidth / 854, 180 * windowHeight / 445)
                .text(txt -> txt
                        .location(-1, 50 * windowHeight / 445)
                        .addLine(info)
                        .scale(1.0F))
                .button(btn -> btn
                        .id("GUI_OK")
                        .background("[local]GUI/button.png", "[local]GUI/button_focus.png")
                        .unClickable("[local]GUI/button_unclickable.png")
                        .size(80 * windowWidth / 854, 20 * windowHeight / 445)
                        .location(20 * windowWidth / 854, 120 * windowHeight / 445)
                        .text("确定")
                        .clickable(true)
                        .click(func1))
                .button(btn -> btn
                        .id("GUI_CANCEL")
                        .background("[local]GUI/button.png", "[local]GUI/button_focus.png")
                        .unClickable("[local]GUI/button_unclickable.png")
                        .size(80 * windowWidth / 854, 20 * windowHeight / 445)
                        .location(150 * windowWidth / 854, 120 * windowHeight / 445)
                        .text("取消")
                        .clickable(true)
                        .click(func2))
                .closable(false)
                .build("[local]GUI/info.png", -1, -1);
        VexViewAPI.openGui(p, gui);
    }

    public void createSquadJoinInfoGui(Player p, String info) {
        int windowWidth = VexViewAPI.getPlayerClientWindowWidth(p);
        int windowHeight = VexViewAPI.getPlayerClientWindowHeight(p);
        VexGui gui = GuiBuilder.builder()
                .size(250 * windowWidth / 854, 180 * windowHeight / 445)
                .text(txt -> txt
                        .location(-1, 50 * windowHeight / 445)
                        .addLine(info)
                        .scale(1.0F))
                .button(btn -> btn
                        .id("GUI_OK")
                        .background("[local]GUI/button.png", "[local]GUI/button_focus.png")
                        .unClickable("[local]GUI/button_unclickable.png")
                        .size(80 * windowWidth / 854, 20 * windowHeight / 445)
                        .location(20 * windowWidth / 854, 120 * windowHeight / 445)
                        .text("自动加入小队")
                        .clickable(true)
                        .click(this::autoJoinSquad))
                .button(btn -> btn
                        .id("GUI_CANCEL")
                        .background("[local]GUI/button.png", "[local]GUI/button_focus.png")
                        .unClickable("[local]GUI/button_unclickable.png")
                        .size(80 * windowWidth / 854, 20 * windowHeight / 445)
                        .location(160 * windowWidth / 854, 120 * windowHeight / 445)
                        .text("取消")
                        .clickable(true)
                        .click(this::createMainGUI))
                .closable(false)
                .build("[local]GUI/info.png", -1, -1);
        VexViewAPI.openGui(p, gui);
    }

    public void createVehicleDispatcherGui(Player p, IVehicleSpawnConquestArea area) {
        int windowWidth = VexViewAPI.getPlayerClientWindowWidth(p);
        int windowHeight = VexViewAPI.getPlayerClientWindowHeight(p);
        int initHeight = 40;
        int distX = 20;
        int distY = 5;
        int buttonWidth = 160;
        int buttonHeight = 25;
        String mapName = GameManager.getInstance().currentGame.mapName + "_" + GameManager.getInstance().currentGame.gameMode;
        VexGui gui = GuiBuilder.builder()
                .size((2 * distX + buttonWidth) * windowWidth / 854, 360 * windowHeight / 445)
                .text(txt -> txt
                        .location(-1, 10 * windowHeight / 445)
                        .addLine("选择载具")
                        .scale(1.0F))
                .button(btn -> btn
                        .id("GUI_INF")
                        .background("[local]GUI/button.png", "[local]GUI/button_focus.png")
                        .unClickable("[local]GUI/button_unclickable.png")
                        .size(buttonWidth * windowWidth / 854, buttonHeight * windowHeight / 445)
                        .location(distX * windowWidth / 854, initHeight * windowHeight / 445)
                        .text("步兵")
                        .clickable(true)
                        .click(
                                (area.getClass().isAnnotationPresent(VehicleSpawn.class))
                                        ? (player) -> MCHHelper.selectVehicle(mapName, player, "inf", area.getIndex())
                                        : area::teleport
                        ))
                .button(btn -> btn
                        .id("GUI_LIGHT")
                        .background("[local]GUI/button.png", "[local]GUI/button_focus.png")
                        .unClickable("[local]GUI/button_unclickable.png")
                        .size(buttonWidth * windowWidth / 854, buttonHeight * windowHeight / 445)
                        .location(distX * windowWidth / 854, (initHeight + (buttonHeight + distY)) * windowHeight / 445)
                        .text("支援载具")
                        .clickable(area.hasLight())
                        .click((player) -> MCHHelper.selectVehicle(mapName, player, "light", area.getIndex())))
                .button(btn -> btn
                        .id("GUI_TANK")
                        .background("[local]GUI/button.png", "[local]GUI/button_focus.png")
                        .unClickable("[local]GUI/button_unclickable.png")
                        .size(buttonWidth * windowWidth / 854, buttonHeight * windowHeight / 445)
                        .location(distX * windowWidth / 854, (initHeight + 2 * (buttonHeight + distY)) * windowHeight / 445)
                        .text("地面载具")
                        .clickable(area.hasTank())
                        .click((player) -> MCHHelper.selectVehicle(mapName, player, "tank", area.getIndex())))
                .button(btn -> btn
                        .id("GUI_AA")
                        .background("[local]GUI/button.png", "[local]GUI/button_focus.png")
                        .unClickable("[local]GUI/button_unclickable.png")
                        .size(buttonWidth * windowWidth / 854, buttonHeight * windowHeight / 445)
                        .location(distX * windowWidth / 854, (initHeight + 3 * (buttonHeight + distY)) * windowHeight / 445)
                        .text("防空车")
                        .clickable(area.hasAA())
                        .click((player) -> MCHHelper.selectVehicle(mapName, player, "aa", area.getIndex())))
                .button(btn -> btn
                        .id("GUI_HELI")
                        .background("[local]GUI/button.png", "[local]GUI/button_focus.png")
                        .unClickable("[local]GUI/button_unclickable.png")
                        .size(buttonWidth * windowWidth / 854, buttonHeight * windowHeight / 445)
                        .location(distX * windowWidth / 854, (initHeight + 4 * (buttonHeight + distY)) * windowHeight / 445)
                        .text("攻击直升机")
                        .clickable(area.hasHeli())
                        .click((player) -> MCHHelper.selectVehicle(mapName, player, "heli", area.getIndex())))
                .button(btn -> btn
                        .id("GUI_SCOUTHELI")
                        .background("[local]GUI/button.png", "[local]GUI/button_focus.png")
                        .unClickable("[local]GUI/button_unclickable.png")
                        .size(buttonWidth * windowWidth / 854, buttonHeight * windowHeight / 445)
                        .location(distX * windowWidth / 854, (initHeight + 5 * (buttonHeight + distY)) * windowHeight / 445)
                        .text("支援直升机")
                        .clickable(area.hasTransHeli())
                        .click((player) -> MCHHelper.selectVehicle(mapName, player, "trans", area.getIndex())))
                .button(btn -> btn
                        .id("GUI_JET")
                        .background("[local]GUI/button.png", "[local]GUI/button_focus.png")
                        .unClickable("[local]GUI/button_unclickable.png")
                        .size(buttonWidth * windowWidth / 854, buttonHeight * windowHeight / 445)
                        .location(distX * windowWidth / 854, (initHeight + 6 * (buttonHeight + distY)) * windowHeight / 445)
                        .text("战斗机")
                        .clickable(area.hasJet())
                        .click((player) -> MCHHelper.selectVehicle(mapName, player, "jet", area.getIndex())))
                .button(btn -> btn
                        .id("GUI_ATKJET")
                        .background("[local]GUI/button.png", "[local]GUI/button_focus.png")
                        .unClickable("[local]GUI/button_unclickable.png")
                        .size(buttonWidth * windowWidth / 854, buttonHeight * windowHeight / 445)
                        .location(distX * windowWidth / 854, (initHeight + 7 * (buttonHeight + distY)) * windowHeight / 445)
                        .text("攻击机")
                        .clickable(area.hasAtkJet())
                        .click((player) -> MCHHelper.selectVehicle(mapName, player, "atkjet", area.getIndex())))
                .button(btn -> btn
                        .id("GUI_FAC")
                        .background("[local]GUI/button.png", "[local]GUI/button_focus.png")
                        .unClickable("[local]GUI/button_unclickable.png")
                        .size(buttonWidth * windowWidth / 854, buttonHeight * windowHeight / 445)
                        .location(distX * windowWidth / 854, (initHeight + 8 * (buttonHeight + distY)) * windowHeight / 445)
                        .text("攻击快艇")
                        .clickable(area.hasFac())
                        .click((player) -> MCHHelper.selectVehicle(mapName, player, "fac", area.getIndex())))
                .button(btn -> btn
                        .id("GUI_CANCEL")
                        .background("[local]GUI/button.png", "[local]GUI/button_focus.png")
                        .unClickable("[local]GUI/button_unclickable.png")
                        .size(buttonWidth * windowWidth / 854, buttonHeight * windowHeight / 445)
                        .location(distX * windowWidth / 854, (initHeight + 9 * (buttonHeight + distY)) * windowHeight / 445)
                        .text("取消")
                        .clickable(true)
                        .click(this::createMainGUI))
                .closable(false)
                .build("[local]GUI/info.png", -1, -1);
        VexViewAPI.openGui(p, gui);
    }

    public void autoJoinSquad(Player p) {
        p.closeInventory();
        Squad.autoJoin(p);
        createMainGUI(p);
    }

    public void changeFaction(Player p) {
        GameManager gm = GameManager.getInstance();
        gm.currentGame.changeFaction(p);
    }

    public void openSlotSetting(Player p) {
        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "cc open weapontype " + p.getName());
    }

    public void openSquadSetting(Player p) {
        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "cc open Squad_" + getCountry2(p) + " " + p.getName());
    }

    public void cancelMainMenu(Player p) {
        GameModelViewHandler.getInstance().createInfoGui(p, "按下 选项-控制-BFMC主菜单 对应的按键重新打开界面", HumanEntity::closeInventory, this::createMainGUI);
    }

    public void setASS(Player p) {
        FactionHelper.setFaction(p, "ASS");
        refreshMainGUI(p);
    }

    public void setREC(Player p) {
        FactionHelper.setFaction(p, "REC");
        refreshMainGUI(p);
    }

    public void setSUP(Player p) {
        FactionHelper.setFaction(p, "SUP");
        refreshMainGUI(p);
    }

    public void setENG(Player p) {
        FactionHelper.setFaction(p, "ENG");
        refreshMainGUI(p);
    }

    public void deploy(Player p) {
        p.setHealth(20.0D);
        if (Cooldown.isCool("Deploy", p)) {
            return;
        }
        p.playSound(p.getLocation(), "custom.Deploy", 20.0F, 1.0F);
        GameManager.getInstance().currentGame.deploy(p);
    }

    private GameModelViewHandler() {
    }

    public static GameModelViewHandler getInstance() {
        if (instance == null) {
            synchronized (GameModelViewHandler.class) {
                if (instance == null) instance = new GameModelViewHandler();
            }
        }
        return instance;
    }
}
